﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WinFormsApp1
{

    public partial class Form1 : Form
    {
        //数组数据
        string[] s = new string[5];
        int i1, i2, i3, i4, i5;

 

        public Form1()
        {
            InitializeComponent();
        }



        //获取输入框数据
        private void num_Init()
        {
            s[0] = textBox1.Text;
            s[1] = textBox2.Text;
            s[2] = textBox3.Text;
            s[3] = textBox4.Text;
            s[4] = textBox5.Text;
            i1 = (int)Convert.ToInt64(s[0]);
            i2 = (int)Convert.ToInt64(s[1]);
            i3 = (int)Convert.ToInt64(s[2]);
            i4 = (int)Convert.ToInt64(s[3]);
            i5 = (int)Convert.ToInt64(s[4]);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                num_Init();
                string sum = (i1 + i2 + i3 + i4 + i5).ToString();
                MessageBox.Show("总和："+sum);
            }
            catch
            {
                MessageBox.Show("输入错误，请您检查您输入的内容。");
            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                num_Init();
                string average = ((i1 + i2 + i3 + i4 + i5)/s.Length).ToString();
                MessageBox.Show("平均数："+average);
            }
            catch
            {
                MessageBox.Show("输入错误，请您检查您输入的内容。");
            }

        }
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                int max = -2147483648;
                num_Init();
                for(int i=0; i<s.Length; i++)
                {
                    if (max < (int)Convert.ToInt64(s[i]))
                    {
                        max = (int)Convert.ToInt64(s[i]);
                    }
                }
                MessageBox.Show("最大值：" + max);

            }
            catch
            {
                MessageBox.Show("输入错误，请您检查您输入的内容。");
            }

        }
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                int min = 2147483647;
                num_Init();
                for (int i = 0; i < s.Length; i++)
                {
                    if (min > (int)Convert.ToInt64(s[i]))
                    {
                        min = (int)Convert.ToInt64(s[i]);
                    }
                }
                MessageBox.Show("最小值：" + min);

            }
            catch
            {
                MessageBox.Show("输入错误，请您检查您输入的内容。");
            }
        }
    }
}
